
import 'package:flutter/material.dart';
import 'package:flutter_module/channel/channel_basic.dart';
import 'package:flutter_module/channel/channel_binary.dart';
import 'package:flutter_module/channel/channel_event.dart';
import 'package:flutter_module/channel/channel_method.dart';

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return WidgetsApp(
      title: 'Flutter Demo',
      color: Colors.white,
      debugShowCheckedModeBanner: false,
      builder: (context, childWeight) {
        return const MyHomePage(title: 'Flutter Demo Home Page');
      },
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text('You have pushed the button this many times:'),
            GestureDetector(
              onTap: () {
                _incrementCounter();
              },
              child: Text(
                '$_counter',
                style: Theme.of(context).textTheme.headlineMedium,
              ),
            ),
            GestureDetector(
              onTap: () {
                print("12");
                callNative("Test", [false]);
              },
              child: Text(
                "调用原生",
                style: Theme.of(context).textTheme.headlineMedium,
              ),
            ),
            GestureDetector(
              onTap: () {
                initEventChannel();
              },
              child: Text(
                "开启Event",
                style: Theme.of(context).textTheme.headlineMedium,
              ),
            ),
            GestureDetector(
              onTap: () {
                stopListen();
              },
              child: Text(
                "停止Event",
                style: Theme.of(context).textTheme.headlineMedium,
              ),
            ),
            GestureDetector(
              onTap: () {
                send("ppp");
              },
              child: Text(
                "发送消息 basic",
                style: Theme.of(context).textTheme.headlineMedium,
              ),
            ),

            GestureDetector(
              onTap: () {
                sendByte();
              },
              child: Text(
                "发送消息 binary",
                style: Theme.of(context).textTheme.headlineMedium,
              ),
            )
          ],
        ),
      ),
    );
  }
}
